<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>绑定手机号</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2>修改绑定手机</h2>
    </header>
</div>
<div class="header-h" style="padding-top: 1.5rem;"></div>
<section class="html_section pr30 pl30 login_section">
    <div class="f26">
        <div class="input-list">
            <p>原绑定手机号</p>
            <div class="line_center" style="color: #737272;" id="tel">137*****886</div>
        </div>
        <div class="input-list">
            <p>新手机号</p>
            <div class="line_center"><input id="phone" class="login_input" placeholder="请输入您的手机号"/></div>
        </div>
        <div class="input-list">
            <p>验证码</p>
            <div class="line_center yzm_box">

                <input class="login_input" id="code" placeholder="请输入验证码"/>
                <div tapmode class="yzm">获取验证码</div>
            </div>
        </div>
    </div>
    <div tapmode class="btn1 mt100 f30" onclick="changeTel()">确定</div>
</section>

</body>

</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/login.js"></script>
<script type="text/javascript">
    var userTel = '';//用户手机号
    apiready = function () {
        setFixStatusBar(); //设置状态栏
        keybackListener()
        //获取手机号
        getUserTel();


    }

    //获取验证码
    $(".yzm").click(function(){
        if(userTel == $("#phone").val()){
            pop.notice('新手机号不能与原手机号一致');
            return;
        }
        hqyzm($("#phone").val(), function (ret) {
            var p = {tel: $("#phone").val(), type: 5};
            pop.loading();
            getAjax(Interface.set_sms, p, function (res) {
                ret()
                pop.close();
            }, function (res, err) {

            })
        });
    });

    function changeTel() {
        var param = {
            token: $api.getStorage('token'),
            code: $('#code').val(),
            tel: $("#phone").val(),
        }
        if(!isDefine(param.tel)){
            pop.notice('请输入新手机号');
            return;
        }
        if(!isDefine(param.code)){
            pop.notice('请输入验证码');
            return;
        }
        pop.loading();
        getAjax(Interface.edit_tel, param, function (res) {
            pop.notice(res.msg);
            pop.close();
            //添加修改手机监听事件
            api.sendEvent({
                name: 'account',
                extra: {}
            });
            setTimeout(function () {
                comeBack();
            },2000)
        }, function (res, err) {
            pop.notice(res.msg);
            pop.close();
        })
    }

    //获取用户信息
    function getMemberInfo() {
        var param = {
            token: $api.getStorage('token')
        }
        getAjax(Interface.memberIndex, param, function (res) {
            $api.setStorage('userInfo', res.data);
        }, function (error) {
            pop.notice('读取数据失败')
        })
    }




    //获取手机号
    function getUserTel() {
        userTel = $api.getStorage('userInfo').tel;
        $("#tel").html(hideTel(userTel))
    }

</script>
